<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>待发布游记管理</title>
    <#include "../common/header.ftl"/>
    <#include "../common/page.ftl"/>

    <script type="text/javascript">
        $(function () {
            $('.inputBtn').click(function() {
                // 排除点击编辑后在点击添加出现的数据遗留问题
                $('#editForm')[0].reset();
                $('#editForm img').attr('src','');
                var data = $(this).data('json');
                if(data){
                    // 页面渲染
                    $('#editForm input[name="id"]').val(data.id);
                    $('#editForm input[name="title"]').val(data.title);
                    $('#editForm input[name="subTitle"]').val(data.subTitle);
                    $('#editForm input[name="travel.id"]').val(data.travelId);
                    $('#editForm input[name="coverUrl"]').val(data.coverUrl);
                    $('#editForm img').attr('src',data.coverUrl);
                    $('#editForm input[name="schedule"]').val(data.schedule);
                    $('#editForm select[name="type"]').val(data.type);
                    // 拼接游记id查询对应的游记(应用已发布游记的高级查询功能)
                    var href = $('#skip').data('href') + data.travelId;
                    $('#skip').attr('href',href);
                }
                $('#showModal').modal('show');
            });
            $('#editForm input[name="file"]').change(function () {
                // 创建文件读取器对象
                var read = new FileReader();
                // 读取文件内容
                read.readAsDataURL(this.files[0]);
                // 将用户选择的图片渲染到页面
                $(read).load(function () {
                    $('#editForm img').attr('src',read.result);
                });
               // $('#editForm img').attr('src',window.URL.createObjectURL(this.files[0]));
            });
            $('.btn_submit').click(function () {
                // 插件原因,不能在循环中return false,没效果
                var flag = false;
                $('#editForm').ajaxSubmit({
                    beforeSubmit: function (params) {
                      $.each(params,function (index, value) {
                          // 遍历表单中所有的参数,找到type
                            if($(value).attr("name")==="type"){
                                // 其对应的值如果是-1说明用户没有选择推荐类型
                                if($(value).attr("value") == -1){
                                   flag = true;
                                }
                            }
                      });
                        if(flag){
                          $.messager.alert("温馨提示","请选择推荐类型!");
                          return false;
                        }
                    },
                    success: function(data){
                        if(data.success){
                           window.location.reload();
                        }
                    }
                });
            });
            // 取消推荐
            $('.removeBtn').click(function () {
                var id = $(this).data('id');
                $.messager.confirm("温馨提示","确定要取消推荐吗?",function () {
                    $.post("/travelCommend/delete.do",{id:id},function (data) {
                        if(data.success){
                            window.location.reload();
                        } else {
                            $.messager.alert("温馨提示","操作" +
                                    "`成功!");
                        }
                    });
                });
            });
        });
    </script>
    <style type="text/css">
        #showModal img {
            width: 100%;
        }
        #showModal .modal-body{
            max-height: 600px;
            overflow-y: auto;
        }
    </style>
</head>

<body>
<form action="/image/upload" enctype="multipart/form-data" method="post" id="imgForm">
    <input name="img" type="file" accept="image/*" style="display: none">
</form>
<div class="container">
<#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
		<#assign currentMenu = "travelCommend" />
				<#include "../common/menu.ftl" />
        </div>
        <div class="col-sm-9">
            <div class="page-header">
                <h3>待发布游记管理</h3>
            </div>
            <div class="row">
                <!-- 提交分页的表单 -->
                <form id="searchForm" class="form-inline" method="post" action="/travelCommend/list.do">
                    <input type="hidden" name="currentPage" id="currentPage" value="1"/>
                    <div class="form-group">
                    </div>
                    <div class="form-group">
                        <label>关键字</label>
                        <input class="form-control" type="text" name="keyword" placeholder="请输入标题"  value="${(qo.keyword)!''}">
                    </div>
                    <div class="form-group">
                        <label>推荐类型</label>
                       <select name="type" class="form-control">
                           <option value="-1">全部</option>
                           <option value="0">周推荐</option>
                           <option value="1">月推荐</option>
                           <option value="2">攻略推荐</option>
                       </select>
                        <script>
                            $('#searchForm select[name=type]').val(${qo.type});
                        </script>
                    </div>
                    <div class="form-group">
                        <button id="query" type="button" class="btn btn-success"><i class="icon-search"></i> 查询</button>
                        <button type="button" class="btn btn-success inputBtn"><i class="icon-plus"></i> 添加</button>
                    </div>
                </form>
            </div>
            <div class="row">
                <table class="table">
                    <thead>
                    <tr>
                        <th>封面</th>
                        <th>标题</th>
                        <th>副标题</th>
                        <th>推荐时间安排</th>
                        <th>推荐类型</th>
                    </tr>
                    </thead>
                    <tbody>
					<#list result.list as vo>
                    <tr>
                        <td><img src="${vo.coverUrl!}" style="width: 60px" alt=""></td>
                        <td>${vo.title!}</td>
                        <td>${vo.subTitle!}</td>
                        <td>${(vo.schedule?string("yyyy-MM-dd"))!}</td>
                        <td>${vo.typeDisplay!}</td>
                        <td>
                            <a href="javascript:;" class="btn btn-success inputBtn" data-json='${(vo.jsonString)!}'><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> 修改</a>
                            <a href="javascript:;" class="btn btn-danger removeBtn" data-id="${vo.id}"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> 取消推荐</a>
                        </td>
                    </tr>
					</#list>
                    </tbody>
                </table>

                <div style="text-align: center;">
                    <ul id="pagination" class="pagination"></ul>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="showModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">编辑/添加</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/travelCommend/saveOrUpdate.do" method="post" id="editForm" enctype="multipart/form-data">
                    <input type="hidden" value="" name="id">
                    <input type="hidden" value="" name="travel.id">
                    <div class="form-group" id="parentDiv">
                        <label class="col-sm-3 control-label">标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="title">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">副标题 ：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="subTitle">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">封面 ：</label>
                        <div class="col-sm-6">
                            <img  src="/upload/acd22908-8780-4e81-8468-8dac6724b8d1.jpeg" style="width: 250px;"/>
                            <input type="file" class="form-control" name="file">
                            <input type="hidden" class="form-control" name="coverUrl">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">推荐日期 ：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="schedule" onclick="WdatePicker()" readonly>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">推荐类型：</label>
                        <div class="col-sm-6">
                            <select name="type" class="form-control">
                                <option value="-1">推荐类型</option>
                                <option value="0">周推荐</option>
                                <option value="1">月推荐</option>
                                <option value="2">攻略推荐</option>
                            </select>
                        </div><br>
                    </div>
                    <div class="form-group" style="text-align:center;">
                        <a href="javascript:void(0)" data-href="/travel/releaseList.do?travelId=" target="_blank" id="skip">点击查看游记文章明细</a>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary btn_submit">保存</button>
                <button type="button" class="btn btn-danger" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>